#!/bin/bash

if [ -z $1 ]
then
	echo " location can not be null"
	exit 1
else	
	PROJECT_DIR=$1
fi

MODULE_NAME=$2

# 查找脚本自身所在目录
SOURCE="$0"
while [ -h "$SOURCE"  ]; do # resolve $SOURCE until the file is no longer a symlink
	DIR="$( cd -P "$( dirname "$SOURCE"  )" && pwd  )"
	SOURCE="$(readlink "$SOURCE")"
	[[ $SOURCE != /*  ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE"  )" && pwd  )"

echo $DIR 
echo $PROJECT_DIR

function createService(){
       serviceFileName=$1
       entity=$2
  #        创建service
        echo "package org.dtrd.modules.${MODULE_NAME}.service;" >> $serviceFileName
        echo ''  >> $serviceFileName
        echo "import com.baomidou.mybatisplus.extension.service.IService;"  >> $serviceFileName
        entity=${mapper//Mapper/''}
        echo "import org.dtrd.modules.${MODULE_NAME}.entity.po.${entity};"  >> $serviceFileName
        echo ''  >> $serviceFileName
        echo '/**'  >> $serviceFileName
        echo '@author 萧'  >> $serviceFileName
        time3=$(date "+%Y-%m-%d %H:%M:%S")
        echo "@date ${time3}"  >> $serviceFileName
        echo "**/"  >> $serviceFileName
        echo "public interface $serviceFileName extends IService<${entity}> {"  >> $serviceFileName
        echo ""  >> $serviceFileName
        echo "}"  >> $serviceFileName
        sed -i "" "s/.java//g" $serviceFileName
}

createService 12 34